//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.goldhuman.xml;

import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.InputStream;
import java.util.Stack;

public class parser extends DefaultHandler {
    private Stack<xmlobject> stack = new Stack();
    private StringBuffer sbcp;

    public parser(String base) {
        this.sbcp = new StringBuffer(base);
    }

    public void startElement(String uri, String localName, String qName, Attributes attributes) {
        try {
            if (this.sbcp.length() > 0) {
                this.sbcp.append(".");
            }

            this.sbcp.append(qName);
            xmlobject obj = (xmlobject)Class.forName(this.sbcp + ".handler").newInstance();
            if (this.stack.empty()) {
                obj.setparent((xmlobject)null);
            } else {
                xmlobject parent = (xmlobject)this.stack.peek();
                obj.setparent(parent);
                parent.setchild(obj);
            }

            this.stack.push(obj);
            obj.setattr(attributes);
        } catch (Exception var7) {
            var7.printStackTrace();
        }

    }

    public void endElement(String uri, String localName, String qName) {
        xmlobject obj = (xmlobject)this.stack.pop();
        if (this.stack.empty()) {
            obj.action();
        } else {
            this.sbcp.delete(this.sbcp.lastIndexOf("."), this.sbcp.length());
        }

    }

    public void characters(char[] ch, int start, int length) {
        xmlobject parent = (xmlobject)this.stack.peek();
        parent.content = parent.content + new String(ch, start, length);
    }

    public static void parse(InputStream is, String base) {
        try {
            SAXParser sap = SAXParserFactory.newInstance().newSAXParser();
            sap.parse(is, new parser(base));
        } catch (Exception var3) {
            var3.printStackTrace();
        }

    }

    public static void parse(InputStream is) {
        parse(is, "");
    }
}
